﻿#region Header

// <file>
//     <copyright see="prj:///doc/copyright.txt"/>
//     <license see="prj:///doc/license.txt"/>
//     <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
//     <version>$Revision: 1965 $</version>
// </file>

#endregion Header

namespace ICSharpCode.TextEditor
{
    using System;
    using System.Drawing;
    using System.Windows.Forms;

    using ICSharpCode.TextEditor.Document;

    #region Delegates

    public delegate void MarginMouseEventHandler(AbstractMargin sender, Point mousepos, MouseButtons mouseButtons);

    public delegate void MarginPaintEventHandler(AbstractMargin sender, Graphics g, Rectangle rect);

    #endregion Delegates

    /// <summary>
    /// This class views the line numbers and folding markers.
    /// </summary>
    public abstract class AbstractMargin
    {
        #region Fields

        [CLSCompliant(false)]
        protected Rectangle drawingPosition = new Rectangle(0, 0, 0, 0);
        [CLSCompliant(false)]
        protected TextArea textArea;

        Cursor cursor = Cursors.Default;

        #endregion Fields

        #region Constructors

        protected AbstractMargin(TextArea textArea)
        {
            this.textArea = textArea;
        }

        #endregion Constructors

        #region Events

        public event MarginMouseEventHandler MouseDown;

        public event EventHandler MouseLeave;

        public event MarginMouseEventHandler MouseMove;

        public event MarginPaintEventHandler Painted;

        #endregion Events

        #region Properties

        public virtual Cursor Cursor
        {
            get {
                return cursor;
            }
            set {
                cursor = value;
            }
        }

        public IDocument Document
        {
            get {
                return textArea.Document;
            }
        }

        public Rectangle DrawingPosition
        {
            get {
                return drawingPosition;
            }
            set {
                drawingPosition = value;
            }
        }

        public virtual bool IsVisible
        {
            get {
                return true;
            }
        }

        public virtual Size Size
        {
            get {
                return new Size(-1, -1);
            }
        }

        public TextArea TextArea
        {
            get {
                return textArea;
            }
        }

        public ITextEditorProperties TextEditorProperties
        {
            get {
                return textArea.Document.TextEditorProperties;
            }
        }

        #endregion Properties

        #region Methods

        public virtual void HandleMouseDown(Point mousepos, MouseButtons mouseButtons)
        {
            if (MouseDown != null) {
                MouseDown(this, mousepos, mouseButtons);
            }
        }

        public virtual void HandleMouseLeave(EventArgs e)
        {
            if (MouseLeave != null) {
                MouseLeave(this, e);
            }
        }

        public virtual void HandleMouseMove(Point mousepos, MouseButtons mouseButtons)
        {
            if (MouseMove != null) {
                MouseMove(this, mousepos, mouseButtons);
            }
        }

        public virtual void Paint(Graphics g, Rectangle rect)
        {
            if (Painted != null) {
                Painted(this, g, rect);
            }
        }

        #endregion Methods
    }
}